package com.rosense.srpingboot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.rosense.srpingboot.entity.UserEntity;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 
 * @author 李岩飞
 * @email eliyanfei@126.com
 * @date 2018年3月10日 下午6:11:19
 */
@Component
@WebListener
public class ContextListener implements ServletContextListener {

	public void contextInitialized(final ServletContextEvent sce) {
		System.out.println("---------------------监听器初始化------------------");
		// lambda表达式内
		new Thread(() -> System.out.println("执行线程")).start();

		List<Integer> list = Arrays.asList(12, 32, 67);

		list.forEach(s -> System.out.println(s));// 遍历打印
		list.forEach(System.out::println);// 遍历打印

		list.stream().filter(s -> s > 20).forEach(System.out::println);// 过滤数据

		List<String> list1 = Arrays.asList("a", "b", "c");
		list1.stream().map(s -> s + "_hello").forEach(System.out::println);// 返回的每个值都有hello
		List<UserEntity> user = list1.stream().map(s -> new UserEntity()).collect(Collectors.toList());

		List<String> list2 = Arrays.asList("a_c", "b_d", "c_e");
		list2.stream().flatMap(s -> Arrays.asList(s.split("_")).stream()).forEach(System.out::println);// a,c,b,d,c,e
	}

	public void contextDestroyed(final ServletContextEvent sce) {

	}
}
